﻿using Ldt.DataEngine.DataFlowParse.Model;
using LdtDataEngin.ModuleDetail.BaseModule;
using LdtDataEngin.ModuleDetail.BaseModule.UserCenter;
using LdtJudge.DataEngine.CallInterface.CommHelp;
using LdtJudge.DataEngine.CallInterface.ConfiCenter;
using LdtJudge.DataEngine.Common;
using LdtJudge.DataEngine.Common.CommHelp;
using LdtJudge.DataEngine.Common.XmlUtility;
using LdtJudge.DataEngine.DataBaseStores;
using LdtJudge.DataEngine.Model.Personnel;
using LdtJudge.DataEngine.Model.XMLConfigModel.AnalysisLabelModel;
using LdtJudge.DataEngine.Model.XMLConfigModel.DataStores;
using LdtJudge.DataEngine.Model.XMLConfigModel.PersonnelConfigModel;
using LdtJudge.DataEngine.Model.XMLConfigModel.SituationPloModel;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace LdtDataEngin.ModuleDetail.CommonModule.SimpleCommon
{
    /// <summary>
    /// 简单通用模块
    /// </summary>
    public class SimpleCommon : AssermBase
    {

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="context"></param>
        /// <param name="moduleName"></param>
        public SimpleCommon(DataContext context, string moduleName)
        {
            base.dataContext = context;
            base.MoudleName = moduleName;
        }


        public void Change()
        {
            AddressConfig analysisLabelListModel = new AddressConfig();
            string xmlconfig = "";
            //获取模块配置
            var configModel = dataContext.DataLayerSys.GetConfigModel(MoudleName);

            if (configModel != null)
            {
                ConfigModel lawDeductionConfig = configModel.ConfigDetail.FirstOrDefault(a => a.Code.ToLower().IndexOf("locationsplit") > -1);
                ConfigModel situationplotrepeatConfig = configModel.ConfigDetail.FirstOrDefault(a => a.Code.ToLower().IndexOf("situationplotrepeat") > -1);
                if (lawDeductionConfig != null && !string.IsNullOrWhiteSpace(lawDeductionConfig.ConfigContent))
                {
                    xmlconfig = lawDeductionConfig.ConfigContent;
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.LoadXml(xmlconfig);
                    analysisLabelListModel = XmlUtility.DeserializeToObject<AddressConfig>(xmlconfig);

                    foreach (CaseTypeLabel caselabe in analysisLabelListModel.caseTypeLabelList.Where(a => a.value == dataContext.DataLayerAns.CaseType))
                    {
                        foreach (AnalysisLabe labe in caselabe.analysisLabes)
                        {
                            ChangeCaseByCause(labe, "");
                        }
                    }
                    string casecause = "";
                    string causename = "";
                    if (dataContext.DataLayerAns.CaseCausesList.Count > 0)
                    {
                        casecause = dataContext.DataLayerAns.CaseCausesList[0].CC_ID;
                        causename = dataContext.DataLayerAns.CaseCausesList[0].CC_Name;
                    }
                    foreach (CaseCuaseLabel causelabe in analysisLabelListModel.CaseCuaseLabelList.Where(a => a.value == casecause))
                    {
                        foreach (AnalysisLabe labe in causelabe.analysisLabes)
                        {
                            ChangeCaseByCause(labe, causename);
                        }
                    }
                    XmlUtilCommon xmlUtilCommon = new XmlUtilCommon() { dataContext = dataContext };
                    dataContext.DataLayerOpt.OptimizationXml = xmlUtilCommon.DataModelByXml(dataContext.DataLayerOpt.SourdatModleList, "");
                }
                else if (situationplotrepeatConfig != null && !string.IsNullOrWhiteSpace(situationplotrepeatConfig.ConfigContent))
                {
                    SuitPlotRepeat(situationplotrepeatConfig.ConfigContent);
                }
                ConfigModel manyPeopleOneSinConfig = configModel.ConfigDetail.FirstOrDefault(x => x.Code.ToLower() == "manypeopleonesin");
                if (manyPeopleOneSinConfig != null && !string.IsNullOrWhiteSpace(manyPeopleOneSinConfig.ConfigContent))
                {
                    try
                    {
                        dataContext.InteractiveShow.LogShow("**************************" + DateTime.Now.ToString("yyyy - MM - dd HH: mm:ss.fff") + "--->开始执行段落标准化处理****************************", LogMessageType.Warn);
                        ManyPeopleOneSinHandle(manyPeopleOneSinConfig.ConfigContent);
                        dataContext.InteractiveShow.LogShow("***************************" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "--->执行段落标准化处理完成*****************************", LogMessageType.Warn);
                    }
                    catch (Exception ex)
                    {
                        dataContext.InteractiveShow.LogShow("段落标准化处理错误：" + ex.ToString(), LogMessageType.Error);
                    }

                }

                ConfigModel processingExtractionConifg = configModel.ConfigDetail.FirstOrDefault(a => a.Code.ToLower() == "processingextractionconifg");

                if (processingExtractionConifg != null && !string.IsNullOrWhiteSpace(processingExtractionConifg.ConfigContent))
                {
                    Processing(processingExtractionConifg.ConfigContent);
                }

                #region 人员ID补充
                ConfigModel personIdSupplyConfig = configModel.ConfigDetail.FirstOrDefault(a => a.Code.ToLower() == "personidsupply");
                if(personIdSupplyConfig!=null && !string.IsNullOrWhiteSpace(personIdSupplyConfig.ConfigContent))
                {
                   
                    try
                    {
                        dataContext.InteractiveShow.LogShow("**************************" + DateTime.Now.ToString("yyyy - MM - dd HH: mm:ss.fff") + "--->开始执行人员ID数据补充****************************", LogMessageType.Warn);
                        PersonIdSupply(personIdSupplyConfig.ConfigContent);
                        dataContext.InteractiveShow.LogShow("***************************" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "--->执行人员ID数据补充完成*****************************", LogMessageType.Warn);
                    }
                    catch (Exception ex)
                    {
                        dataContext.InteractiveShow.LogShow("人员ID数据补充异常：" + ex.ToString(), LogMessageType.Error);
                    }
                }
                #endregion
            }
        }

        public void Processing(string cofing)
        {
            ProcessingCofing processingCofing= XmlUtility.DeserializeToObject<ProcessingCofing>(cofing);
            if (processingCofing!=null && processingCofing.originalTextList.Count>0)
            {
                foreach (OriginalTextModel orgmodel in processingCofing.originalTextList)
                {
                    string xmlpath = orgmodel.XmlPath.Split(new string[] { "/@" }, System.StringSplitOptions.None)[0];
                    string attname = orgmodel.XmlPath.Split(new string[] { "/@" }, System.StringSplitOptions.None)[1];
                    dataContext.InteractiveShow.LogShow("查询xpath为" + xmlpath + "查询属性为:" + attname);
                    DataModel dataModel = XmlUtility.ConditionFirstOrDefaultDataModel(dataContext.DataLayerOpt.SourdatModleList, "", xmlpath);
                    if (dataModel.AttributesList.FirstOrDefault(a=> a.Name==attname)!=null)
                    {
                        string attvalue = dataModel.AttributesList.FirstOrDefault(a => a.Name == attname).sourceList.FirstOrDefault(a => a.IsCheck == "1").SaveValue;
                        dataContext.InteractiveShow.LogShow("查询结果"+attvalue);
                        List<string> valueList= Ldt.DataEngine.RuleAssemble.RuleParseClass.GetParseRegCodeList(orgmodel.Regcode, new List<string>() { attvalue }).ToList();
                        if (valueList.Count>0)
                        {
                            dataContext.InteractiveShow.LogShow("执行结果" + valueList[0]);
                            foreach (ValuesModel valuesModel in orgmodel.valueList)
                            {
                                string xmlpathAT = valuesModel.XmlPath.Split(new string[] { "/@" }, System.StringSplitOptions.None)[0];
                                string attnameAT = valuesModel.XmlPath.Split(new string[] { "/@" }, System.StringSplitOptions.None)[1];
                                DataModel dataModelSet = XmlUtility.ConditionFirstOrDefaultDataModel(dataContext.DataLayerOpt.SourdatModleList, "", xmlpathAT);
                                ATTModel(dataModelSet.AttributesList, attnameAT, valueList[0]);
                            }
                        }

                    }

                }
            }
            XmlUtilCommon xmlUtilCommon = new XmlUtilCommon() { dataContext = dataContext };
            dataContext.DataLayerOpt.OptimizationXml = xmlUtilCommon.DataModelByXml(dataContext.DataLayerOpt.SourdatModleList, "");
        }

        #region 省市县拆分模块
        public void ChangeCaseByCause(AnalysisLabe labe, string causename)
        {
            string xmlpath = labe.Value;
            string[] str = labe.courtxpath.Split('@');
            string courtxpath = str[0];
            string courtxpathname = str[1];
            string courtname = "";

            DataModel courtModel = new DataModel();
            DataModel courtModels = new DataModel();
            List<DataModel> datamodeList = new List<DataModel>();
            if (string.IsNullOrEmpty(causename))
            {
                courtModels = dataContext.DataLayerOpt.SourdatModleList.FirstOrDefault(a => a.XmlPath == xmlpath);
                if (courtModels != null)
                {
                    datamodeList = dataContext.DataLayerOpt.SourdatModleList.Where(a => a.XmlPath == xmlpath).ToList();
                }
            }
            else
            {
                courtModels = dataContext.DataLayerOpt.SourdatModleList.FirstOrDefault(a => a.XmlPath == causename + "/" + xmlpath || a.XmlPath == xmlpath);
                if (courtModels != null)
                {
                    datamodeList = dataContext.DataLayerOpt.SourdatModleList.Where(a => a.XmlPath == causename + "/" + xmlpath).ToList();
                }
            }

            courtModel = dataContext.DataLayerOpt.SourdatModleList.FirstOrDefault(a => a.XmlPath == courtxpath);
            if (courtModel != null)
            {
                AttributeInfo attribute = courtModel.AttributesList.FirstOrDefault(a => a.Name == courtxpathname);
                if (attribute != null)
                {
                    courtname = attribute.sourceList.FirstOrDefault(a => a.IsCheck == "1").SaveValue;
                }
            }
            foreach (DataModel model in datamodeList)
            {

                if (model.AttributesList.FirstOrDefault(a => a.Name == labe.originaltext) != null)
                {
                    string originaltext = model.AttributesList.FirstOrDefault(a => a.Name == labe.originaltext).sourceList.FirstOrDefault(a => a.IsCheck == "1").SaveValue;
                    var addressList = AnalysisLabelClass.extract.ExtractAddress(originaltext);
                    if (addressList.Count > 0)
                    {
                        #region 省级信息处理
                        if (!string.IsNullOrEmpty(addressList[0].Provice))
                        {
                            ATTModel(model.AttributesList, labe.province, addressList[0].Provice);
                        }
                        #endregion

                        #region 地级信息处理
                        if (!string.IsNullOrEmpty(addressList[0].City))
                        {
                            ATTModel(model.AttributesList, labe.cities, addressList[0].City);
                        }
                        #endregion



                        if (!string.IsNullOrEmpty(addressList[0].County))
                        {
                            ATTModel(model.AttributesList, labe.county, addressList[0].County);
                        }

                        #region 乡级信息处理
                        if (!string.IsNullOrEmpty(addressList[0].Village))
                        {
                            ATTModel(model.AttributesList, labe.township, addressList[0].Village);
                        }
                        #endregion

                        #region 村级信息处理

                        ATTModel(model.AttributesList, labe.address, addressList[0].DetailAddress);

                        #endregion
                    }



                }
            }
        }

        /// <summary>
        /// 添加属性值
        /// </summary>
        /// <param name="AttributeList">属性集合</param>
        /// <param name="AttributeName">属性名称</param>
        /// <param name="AttributeValue">属性值</param>
        public void ATTModel(List<AttributeInfo> AttributeList, string AttributeName, string AttributeValue)
        {
            if (AttributeList.FirstOrDefault(a => a.Name == AttributeName) != null)
            {
                AttributeList.FirstOrDefault(a => a.Name == AttributeName).sourceList.FirstOrDefault(a => a.IsCheck == "1").SaveValue = AttributeValue;
            }
            else
            {
                Source source = new Source();
                source.SaveValue = AttributeValue;
                source.SourceCode = dataContext.DataLayerAns.SourceCode;
                source.IsCheck = "1";

                AttributeInfo attribute = new AttributeInfo();
                attribute.Name = AttributeName;
                attribute.sourceList = new List<Source>();
                attribute.sourceList.Add(source);
                AttributeList.Add(attribute);
            }
        }
        #endregion

        #region 情形情节去重信息

        public void SuitPlotRepeat(string ConfigXml)
        {
            SituationPlotConfigModel situationPlotConfigModel = new SituationPlotConfigModel();
            situationPlotConfigModel = XmlUtility.DeserializeToObject<SituationPlotConfigModel>(ConfigXml);
            if (situationPlotConfigModel != null)
            {
                SituationPlotCaseType situationPlotCaseType = situationPlotConfigModel.situationPlotCaseTypeList.FirstOrDefault(a => a.code.ToLower() == dataContext.DataLayerAns.CaseType.ToLower());
                if (situationPlotCaseType != null)
                {
                    SituationPlotBookType situationPlotBookType = situationPlotCaseType.situationPlotBookTypeList.FirstOrDefault(a => a.code.ToLower() == dataContext.DataLayerAns.SourceCode.ToLower());
                    if (situationPlotBookType != null)
                    {
                        if (situationPlotBookType.situationPlotMergeList.Count > 0)
                        {
                            PlotRepeat(situationPlotBookType.situationPlotMergeList);
                        }

                        SituationPlotCaseCuase situationPlotCaseCuase = situationPlotBookType.situationPlotCaseCuaseList.FirstOrDefault(a => a.code == dataContext.DataLayerAns.CaseCausesList[0].CC_ID);

                        if (situationPlotCaseCuase != null && situationPlotCaseCuase.situationPlotMergeList != null && situationPlotCaseCuase.situationPlotMergeList.Any())
                        {
                            PlotRepeat(situationPlotCaseCuase.situationPlotMergeList);
                        }
                    }
                }
            }

        }
        public GetSysCaseCause dALSYS_CaseCause = new GetSysCaseCause();

        public void PlotRepeat(List<SituationPlotMerge> situationPlotMergeList)
        {

            foreach (SituationPlotMerge situationPlotMerge in situationPlotMergeList)
            {
                DataModel dataModelRoot = XmlUtility.ConditionFirstOrDefaultDataModel(dataContext.DataLayerOpt.SourdatModleList, "", situationPlotMerge.path);
                if (dataModelRoot != null)
                {
                    List<DataModel> dataModelList = dataContext.DataLayerOpt.SourdatModleList.Where(a => a.ParentId == dataModelRoot.ID)?.ToList();
                    string attName = "";
                    if (situationPlotMerge.type == "1")
                    {
                        attName = "情形ID";
                    }
                    else
                    {
                        attName = "情节ID";
                    }
                    List<DataModel> dataModels1RomveList = new List<DataModel>();
                    foreach (DataModel mode in dataModelList)
                    {
                        string id = mode.AttributesList.FirstOrDefault(a => a.Name == attName).sourceList.FirstOrDefault(a => a.IsCheck == "1").SaveValue;
                        List<string> liststr = new List<string>();
                        var causemodel = dALSYS_CaseCause.GetModel(id);
                        liststr = causemodel.AllParentId.Split(',').ToList();
                        List<DataModel> dataModels = dataModelList.Where(a => a.AttributesList.FirstOrDefault(b => b.Name == attName).sourceList.FirstOrDefault(c => c.IsCheck == "1")?.SaveValue != id
                        && liststr.Contains(a.AttributesList.FirstOrDefault(a => a.Name == attName).sourceList.FirstOrDefault(a => a.IsCheck == "1").SaveValue))?.ToList();
                        if (dataModels.Count > 0)
                        {
                            dataModels1RomveList.AddRange(dataModels);
                        }

                    }

                    if (dataModels1RomveList.Count > 0)
                    {
                        foreach (DataModel dataModel in dataModels1RomveList)
                        {
                            dataContext.DataLayerOpt.SourdatModleList.Remove(dataModel);
                        }
                    }
                }
            }
        }

        #endregion

        #region 多人一罪段落数据处理
        public void ManyPeopleOneSinHandle(string xmlConfig)
        {
            var paragraphList = dataContext.DataLayerAns.Duanluos;
            //当事人基本信息集合
            List<PartyBasicModel> partyBasicInfos = new List<PartyBasicModel>();
            //当事人基本信息段落集合
            List<string> partyParagraphs = new List<string>();
            //犯罪经历段落集合
            List<string> crimeParagraphs = new List<string>();
            string crimeTypeDesc = string.Empty;
            string currentParagrathCode = string.Empty;
            if (paragraphList != null && paragraphList.Any())
            {
                if (!string.IsNullOrWhiteSpace(xmlConfig))
                {
                    PartyInfoHandleModel handleConfig = XmlSerializeHelper.DESerializer<PartyInfoHandleModel>(xmlConfig);
                    if (handleConfig != null)
                    {
                        var caseType = handleConfig.CaseTypes.FirstOrDefault(x => x.Code.ToLower() == dataContext.DataLayerAns.CaseType.ToLower());
                        if (caseType != null)
                        {
                            var docType = caseType.Doctypes.FirstOrDefault(x => x.Code.ToLower() == dataContext.DataLayerAns.FengXiCanShu.Juanzongbianhao.ToLower());
                            if (docType != null)
                            {
                                var paragrapthConfig = docType.Paragraph;
                                if (paragrapthConfig != null && !string.IsNullOrWhiteSpace(paragrapthConfig.Code))
                                {

                                    //拆分后段落集合配置
                                    var subConfig = paragrapthConfig.Subparagraph;
                                    //获取当事人信息段落原文
                                    var paragraph = paragraphList.FirstOrDefault(x => x.Duanluobianhao.ToLower() == paragrapthConfig.Code.ToLower());
                                    var originalTxt = paragraph.Duanluoneirong;
                                    if (!string.IsNullOrWhiteSpace(originalTxt))
                                    {
                                        //拆分段落原文，获取当事人信息集合和当事人犯罪经历集合
                                        var allInfos = Ldt.DataEngine.RuleAssemble.RuleParseClass.GetParseRegCodeList(paragrapthConfig.SplitReg, originalTxt);
                                        if (allInfos != null && allInfos.Any())
                                        {
                                            foreach (var infoItem in allInfos)
                                            {
                                                if (subConfig != null)
                                                {
                                                    if (!string.IsNullOrWhiteSpace(subConfig.TypeReg))
                                                    {
                                                        if (!string.IsNullOrWhiteSpace(infoItem))
                                                        {
                                                            //通过正则获取段落类型 1.当事人信息 2.犯罪经历
                                                            var infoType = Ldt.DataEngine.RuleAssemble.RuleParseClass.GetParseRegCodeValue(subConfig.TypeReg, infoItem);
                                                            if (!string.IsNullOrWhiteSpace(infoType))
                                                            {
                                                                var typeCode = infoType.Split(":")[0];
                                                                if (typeCode == "1")
                                                                {
                                                                    partyParagraphs.Add(infoItem);
                                                                }
                                                                else if (typeCode == "2")
                                                                {
                                                                    crimeTypeDesc = infoType.Split(":")[1];
                                                                    crimeParagraphs.Add(infoItem);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            if (partyParagraphs.Count > 0)
                                            {
                                                //解析当事人段落数据集合
                                                partyBasicInfos = this.ParsePartyInfo(partyParagraphs, subConfig);
                                            }

                                            if (partyBasicInfos.Any() && crimeParagraphs.Any())
                                            {
                                                if (crimeParagraphs.Count == 1)
                                                {
                                                    if (partyBasicInfos.Count == 1)
                                                    {
                                                        MorePartyNoNameFill(partyBasicInfos, crimeParagraphs, subConfig);
                                                    }
                                                    else
                                                    {
                                                        MorePartySingleCrimeFill(partyBasicInfos, crimeParagraphs.FirstOrDefault(), subConfig);
                                                    }
                                                }
                                                else
                                                {
                                                    var firstCrime = crimeParagraphs.FirstOrDefault();
                                                    //犯罪经历标题
                                                    string crimeTitle = firstCrime.Split("：")[0];
                                                    string crimeName = string.Empty;
                                                    if (!string.IsNullOrWhiteSpace(crimeTitle))
                                                    {
                                                        //通过正则获取犯罪经历标题中的姓名
                                                        crimeName = Ldt.DataEngine.RuleAssemble.RuleParseClass.GetParseRegCodeValue(subConfig.CrimeNameReg, crimeTitle);
                                                        //crimeTitle = crimeTitle.Replace(crimeTypeDesc, "");
                                                    }
                                                    //犯罪经历标题是否包含当事人姓名
                                                    bool isHaveName = (!string.IsNullOrWhiteSpace(crimeName));
                                                    if (isHaveName)
                                                    {
                                                        MorePartyHaveNameFill(partyBasicInfos, crimeParagraphs, subConfig, crimeTypeDesc);
                                                    }
                                                    else
                                                    {
                                                        MorePartyNoNameFill(partyBasicInfos, crimeParagraphs, subConfig);
                                                    }
                                                }
                                                StringBuilder fillAfterInfo = new StringBuilder();
                                                foreach (var partyitem in partyBasicInfos)
                                                {
                                                    var infos = partyitem.PartyInfos;
                                                    string infoStr = string.Join("", infos);
                                                    fillAfterInfo.AppendLine(infoStr);
                                                }
                                                dataContext.InteractiveShow.LogShow("@段落标准化结果数据" + fillAfterInfo.ToString(), LogMessageType.Info);
                                                foreach (var duanluo in dataContext.DataLayerAns.Duanluos.Where(x => x.Duanluobianhao.ToLower() == paragrapthConfig.Code.ToLower()))
                                                {
                                                    duanluo.Duanluoneirong = fillAfterInfo.ToString();
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 解析当事人信息段落数据
        /// </summary>
        private List<PartyBasicModel> ParsePartyInfo(List<string> infos, Subparagraph subConfig)
        {
            List<PartyBasicModel> result = new List<PartyBasicModel>();
            if (infos != null && infos.Any())
            {
                for (int i = 0; i < infos.Count; i++)
                {
                    PartyBasicModel model = new PartyBasicModel();
                    model.DataIndex = i;

                    if (!string.IsNullOrWhiteSpace(subConfig.NameReg))
                    {
                        model.Name = Ldt.DataEngine.RuleAssemble.RuleParseClass.GetParseRegCodeValue(subConfig.NameReg, infos[i]);
                    }
                    if (model.PartyInfos == null)
                        model.PartyInfos = new List<string>();
                    model.PartyInfos.Add(infos[i]);
                    result.Add(model);
                }
            }
            return result;
        }

        /// <summary>
        /// 段落标准化数据处理（多条犯罪经历段落标题不包含姓名模式）
        /// </summary>
        /// <param name="partys">当事人数据集合</param>
        /// <param name="crimes">犯罪经历集合</param>
        /// <param name="subConfig">段落标准化配置</param>
        private void MorePartyNoNameFill(List<PartyBasicModel> partys, List<string> crimes, Subparagraph subConfig)
        {
            for (int i = 0; i < crimes.Count; i++)
            {
                string infoTitle = crimes[i].Split("：")[0];
                var crimeOrg = crimes[i].Replace($"{infoTitle}：", "");
                var crimeInfos = Ldt.DataEngine.RuleAssemble.RuleParseClass.GetParseRegCodeList(subConfig.SplitReg, crimeOrg);
                if (crimeInfos.Any())
                {
                    foreach (var partyBasic in partys.Where(x => x.DataIndex == i))
                    {
                        crimeInfos[0] = $"{infoTitle}：{crimeInfos[0]}";
                        partyBasic.PartyInfos.AddRange(crimeInfos);
                    }
                }
            }
        }

        /// <summary>
        /// 段落标准化数据处理（多条犯罪经历段落标题包含姓名模式）
        /// </summary>
        /// <param name="partys">当事人数据集合</param>
        /// <param name="crimes">犯罪经历集合</param>
        /// <param name="subConfig">段落标准化配置</param>
        /// <param name="crimeTypeDesc">犯罪经历段落标题</param>
        private void MorePartyHaveNameFill(List<PartyBasicModel> partys, List<string> crimes, Subparagraph subConfig, string crimeTypeDesc)
        {
            for (int i = 0; i < crimes.Count; i++)
            {
                var crimeTitle = crimes[i].Split("：")[0];
                var crimeOrg = crimes[i].Replace($"{crimeTitle}：", "");
                var crimeInfos = Ldt.DataEngine.RuleAssemble.RuleParseClass.GetParseRegCodeList(subConfig.SplitReg, crimeOrg);
                if (crimeInfos.Any())
                {
                    string infoTitle = crimes[i].Split("：")[0];
                    if (!string.IsNullOrWhiteSpace(crimeTitle))
                    {
                        crimeTitle = crimeTitle.Replace(crimeTypeDesc, " ");
                    }
                    var name = crimeTitle.Trim();
                    foreach (var partyBasic in partys.Where(x => x.Name.Equals(name)))
                    {
                        crimeInfos[0] = $"{infoTitle}：{crimeInfos[0]}";
                        partyBasic.PartyInfos.AddRange(crimeInfos);
                    }
                }
            }
        }

        /// <summary>
        /// 段落标准化数据处理（单条犯罪经历段落中包含多个当事人姓名模式）
        /// </summary>
        /// <param name="partys">当事人数据集合</param>
        /// <param name="crimeTxt">犯罪经历集合</param>
        /// <param name="subConfig">段落标准化配置</param>
        private void MorePartySingleCrimeFill(List<PartyBasicModel> partys, string crimeTxt, Subparagraph subConfig)
        {
            if (!string.IsNullOrWhiteSpace(crimeTxt))
            {
                var crimeTitle = crimeTxt.Split("：")[0];
                var crimeOrg = crimeTxt.Replace($"{crimeTitle}：", "");
                var crimeInfos = Ldt.DataEngine.RuleAssemble.RuleParseClass.GetParseRegCodeList(subConfig.SplitReg, crimeOrg);
                if (crimeInfos.Any())
                {
                    List<string> partyNames = partys.Select(x => x.Name).ToList();
                    string currentName = string.Empty;
                    foreach (var crime in crimeInfos)
                    {
                        bool isChange = false;
                        foreach (var name in partyNames)
                        {
                            if (crime.Contains(name))
                            {
                                if (!name.Equals(currentName))
                                {
                                    currentName = name;
                                    isChange = true;
                                }
                            }
                        }
                        if (!string.IsNullOrWhiteSpace(currentName))
                        {
                            foreach (var partyBasic in partys.Where(x => x.Name.Equals(currentName)))
                            {
                                if (isChange)
                                {
                                    var firstCrime = $"{crimeTxt.Split("：")[0]}：{crime}";
                                    partyBasic.PartyInfos.Add(firstCrime);
                                }
                                else
                                {
                                    partyBasic.PartyInfos.Add(crime);
                                }

                            }
                        }
                    }
                }
            }

        }
        #endregion

        #region 人员ID补充处理
        /// <summary>
        /// 人员Id数据补充
        /// </summary>
        /// <param name="config">配置内容</param>
        private void PersonIdSupply(string config)
        {
            PersonIdSupplyModel supplyModel= XmlUtility.DeserializeToObject<PersonIdSupplyModel>(config);
            UserCenterProxy userProxy = new UserCenterProxy();
            if(supplyModel!=null)
            {
                //获取案件类型配置
                var caseType = supplyModel.CaseTypes.FirstOrDefault(x => x.Code.Split(",").Contains(dataContext.DataLayerAns.CaseType));
                if(caseType!=null)
                {
                    //获取法院数据
                    string courtPath = caseType.court.path;
                    string courtIdAttr = caseType.court.idattr;
                    string courtId = string.Empty;
                    DataModel courtData = dataContext.DataLayerOpt.SourdatModleList.FirstOrDefault(x => x.XmlPath == courtPath);
                    if(courtData!=null)
                    {
                        courtId= courtData.AttributesList.FirstOrDefault(a => a.Name == courtIdAttr).sourceList.FirstOrDefault(a => a.IsCheck == "1").SaveValue;
                    }
                    var personnels = caseType.Personner.PersonDetails;
                    if(string.IsNullOrWhiteSpace(courtId))
                    {
                        dataContext.InteractiveShow.LogShow("法院Id数据为空，未执行人员Id补充功能");
                    }
                    else
                    {
                        if (personnels != null && personnels.Any())
                        {
                            foreach (var personItem in personnels)
                            {
                                if (dataContext.DataLayerOpt.SourdatModleList.Any(x => x.XmlPath == personItem.path))
                                {
                                    string userType = string.Empty;
                                    if (personItem.path.Contains("案件办理人员"))
                                        userType = "案件办理人员";
                                    else if (personItem.path.Contains("审判执行组织成员"))
                                        userType = "审判执行组织成员";
                                    foreach (var userItem in dataContext.DataLayerOpt.SourdatModleList.Where(x => x.XmlPath == personItem.path))
                                    {
                                        AttributeInfo userIdInfo = userItem.AttributesList.FirstOrDefault(a => a.Name == personItem.idattr);
                                        if (userIdInfo==null)
                                        {
                                            var userName = userItem.AttributesList.FirstOrDefault(a => a.Name == personItem.nameattr).sourceList.FirstOrDefault(a => a.IsCheck == "1").SaveValue;
                                            if (!string.IsNullOrWhiteSpace(userName))
                                            {
                                                string url = ConfigRetrieval.GetConfigRetrieval.GetAppSettingString("LdtUserCenter") + "/api/v2/getUserInfoByUserName";
                                                var param = new
                                                {
                                                    courtId = courtId,
                                                    username = userName
                                                };
                                                string postData = JsonConvert.SerializeObject(param);
                                                dataContext.InteractiveShow.LogShow($"{userType}【{userName}】调用用户中心获取用户信息接口【{url}】,入参：{postData}");
                                                //调用用户中心接口，获取用户信息
                                                var userResult = userProxy.GetUserInfoByName(url,postData);
                                                dataContext.InteractiveShow.LogShow($"{userType}【{userName}】调用用户中心获取用户信息接口结果：{JsonConvert.SerializeObject(userResult)}");
                                                if (userResult.Result.Code=="1")
                                                {
                                                    string userId = userResult.Body.FirstOrDefault(x=>!string.IsNullOrWhiteSpace(x.UserId))?.UserId;
                                                    if(!string.IsNullOrWhiteSpace(userId))
                                                    {
                                                        AddAttrAttribute(personItem.idattr, userId, userItem,true);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        #endregion

        /// <summary>
        /// 属性增加方法
        /// </summary>
        /// <param name="AttributeName">属性名称</param>
        /// <param name="AttributeValue">属性值</param>
        /// <param name="dataModel">节点实体</param>
        private void AddAttrAttribute(string AttributeName, string AttributeValue, DataModel dataModel,bool isAnalysis=false)
        {

            AttributeInfo attribute = dataModel.AttributesList.FirstOrDefault(a => a.Name == AttributeName);
            if (attribute == null)
            {
                AttributeInfo attribute1Conent = new AttributeInfo();
                attribute1Conent.Name = AttributeName;
                attribute1Conent.sourceList = new List<Source>();
                Source source = new Source();
                source.SaveValue = AttributeValue;
                source.SourceCode = dataContext.DataLayerAns.SourceCode;
                source.IsCheck = "1";
                if(isAnalysis)
                    source.AnalysisStatus = "1";
                attribute1Conent.sourceList.Add(source);
                dataModel.AttributesList.Add(attribute1Conent);
            }
            else
            {
                Source source = attribute.sourceList.FirstOrDefault(a => a.SourceID == dataContext.DataLayerAns.SourceCode);
                if (source == null)
                {
                    Source sources = new Source();
                    sources.SaveValue = AttributeValue;
                    sources.SourceCode = dataContext.DataLayerAns.SourceCode;
                    sources.IsCheck = "1";
                    if (isAnalysis)
                        source.AnalysisStatus = "1";
                    attribute.sourceList.Add(sources);
                }
                else
                {
                    source.SaveValue = AttributeValue;
                }
            }
        }
    }
}
